import { Component } from '@angular/core';
import { ModalService, ConfirmService, Pagination } from 'ng-tui';
import { AccountService } from '../../services/account.service';
import { Closed } from '../../interfaces/inventory.interfaces';
import { ApiData, SearchParams } from '../../../../cores/classes';
import { RequestService, GlobalService } from '../../../../cores/services';
@Component({
    template: `
    <div class="modal-header">
    <h5 class="modal-title">添加应收</h5>
    <button (click)="close()" type="button" class="close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<ts-datepicker #datepicker="tsDatepicker" [(ngModel)]="closed.beginOfPeriodDate"
[color]="global.params.color" name="beginOfPeriodDate"></ts-datepicker>
<div class="modal-body">
    <div style="flex: 1 1 auto;padding: 1.25rem 0rem 1.25rem 0rem;">
        <div class="form-group row" style="display:flex;">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">客户名称</label>
            <div class="col-sm-4">
            <input type="text" [(ngModel)]="closed.customerId" class="form-control">
            </div>
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">期初日期</label>
            <div class="col-sm-4">
            <input tsToggle [target]="datepicker" [bind]="datepicker"
            [value]="closed.beginOfPeriodDate " placeholder="请选择日期" type="text" class="form-control ht bg-white pointer required">
            </div>
        </div>

        <div class="form-group row" style="display:flex;">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">应收单据</label>
            <div class="col-sm-4">
                <input type="text"  [(ngModel)]="closed.receivableReceiptNumber" class="form-control">
            </div>
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">应收总金额</label>
            <div class="col-sm-4">
                <input type="text"  [(ngModel)]="closed.receivableTotalMoney"  class="form-control">
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button tsBtn (click)="modal.dismiss()">取消</button>
        <button tsBtn loading color="success" (submit)="confirmSave($event)">保存</button>
    </div>`,
})
export class ModalclosedtComponent {
    // name="couponName"[(ngModel)]="closed.couponName"
    // content = '...';
    // voucher: Voucher = { id: 0, isActive: 1, couponName: '', };
    changg: number;
    loading = false;
    search = new SearchParams({ status: '' });
    pagination = new Pagination();
    closed: Closed = {};
    nowD = new Date();



    constructor(
        private modal: ModalService,
        private accountService: AccountService,
        private confirm: ConfirmService,
        public global: GlobalService,
    ) { }


    close() {
        this.modal.dismiss();
    }

    confirmSave(btn: any) {
        (this.closed.id > 0 ? this.accountService.updatesurplus(this.closed) : this.accountService.surplusadd(this.closed))
            .subscribe({
                next: () => this.modal.close(),
                complete: () => btn.dismiss()
            });
    }
    // testa() {
    //     this.voucherService.insertCompany(this.voucher).subscribe({
    //         next: res => {
    //             this.confirm.success('添加成功', `'${this.voucher.couponName}`);
    //             this.close();
    //             this.loadDatas();

    //         }
    //     });
    // }


}

